/*******************************************************************************
 * 
 * Copyright:
 * 
 * License:
 * 
 * Authors: SALMON Charles
 * 
 ******************************************************************************/

/*******************************************************************************
 * 
 ******************************************************************************/

/**
 * A form to handle the answers of a given survey
 */
qx.Class.define("bip.ui.survey.FillSurveyForm",
{
  extend : qx.ui.form.Form,
  
  events :
  {
    "ready" : "qx.event.type.Event"
  },
  
  construct : function()
  {
    this.base(arguments);
    
    // TOPICS SERVICE
	var service = bip.services.Survey.getInstance();
	service.addListener("error",function(evt) {
		alert("Error:"+evt.getData().getMessage());
	},this);
	service.addListener("loaded",function(evt){
		var data = evt.getData();
		for(var i=0;i<data.length;i++) {
			var model = data.getItem(i);
			if (model.getJavaClass().match(/^.*Topic/i)) {
				this.addGroupHeader(model.getName());
			} else {
				this.debug(qx.dev.Debug.debugProperties(model));
				var question = new bip.ui.form.survey.QuestionField();
				question.set({
			    	description:model.getDescription(),
			    	minvalue:model.getMinValue(),
			    	maxvalue:model.getMaxValue()
			    });
			    question.setWidth(200);
			    this.add(question,model.getName(),null,model.getName());
			}
		}
		this.fireEvent("ready");
	},this);
	
    //service.fetchSurvey();
    
    
  },
  
	/*
	 *****************************************************************************
    MEMBERS
	 *****************************************************************************
	 */

 	members :
 	{
 		
 		
 	},
 	
	/*
	 * ****************************************************************************
	 * DESTRUCTOR
	 * ****************************************************************************
	 */

	destruct : function() {
		this._disposeObjects()
	}

  
});